package com.pearadmin.system.timedTask;

import com.pearadmin.system.domain.SysAxis;
import com.pearadmin.system.service.ISysAxisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Random;

@Slf4j
@Component //把此类托管给Spring
public class MysqlTimedTask {

    @Resource
    private ISysAxisService iSysAxisService;

    //定时改变数据库的数据
    @Scheduled(cron = "0/5 * * * * ?") // cron 表达式，每5秒执行一次
    public void doTask(){
        Random random = new Random();
        //随机生成1000--8000之间的数
        long rev = random.nextInt(8000) % (8000 - 1000 + 1) + 1000;
        long axisId = 1;
        SysAxis sysAxis =new SysAxis();
        sysAxis.setAxisId(axisId);
        sysAxis.setAxisSpace("机房1");
        sysAxis.setAxisType("型号1");
        sysAxis.setAxisState("正常");
        sysAxis.setAxisPrc("/admin/images/axis_prc1.jpeg");
        sysAxis.setCurrentOperator("Ryan");
        sysAxis.setAxisRev(rev);

        int success = iSysAxisService.updateSysAxis(sysAxis);
        if(success>0){
//            System.out.println("成功改变sql"+rev);
        }else {
            System.out.println("失败"+rev);
        }

    }
}
